home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Pictures / TIFF / Tiff Utilties / Tiff Window DEMO / set color.c < prev    next >
C/C++ Source or Header  |  1990-03-20  |  6KB  |  133 lines

  1. #include "my color.h"
  2. /*
  3.     This program modual contains the Initializing and Modification code to 
  4.     colorize the windows and scroll bars.
  5. */
  6.  
  7. void    set_color(aWindow)    /*     When a new window has been created, I'll initialize 
  8.                                 the  new window's colors to these default values, change 
  9.                                 them as you see fit.  See Inside Macintosh Vol 5, page 202,
  10.                                 The Window Color Tables paragraph for a detailed explaination
  11.                                 of what is going on here.  Each window should get its own
  12.                                 unique Color Table.
  13.                             */
  14. CWindowPtr    aWindow;
  15. {
  16. CWindowPeek        peek;
  17. ControlHandle    control;
  18. CTabHandle    new_color_handle;
  19.     GetPort(&savedPort);        /* Save the Graf Port */
  20. /*
  21.     in order to display  a window in color, I must first create a color table that 
  22.     will contain color definitions for all the parts of the window.  Each window 
  23.     should have its own unique color table.  If we don't give each window a 
  24.     unique color table, then color changes in one window will affect all 
  25.     the windows. Read Inside Mac Vol. 5, page V-48 for a definition of the color 
  26.     table record. Page V-134 contains even more info on color tables and on how
  27.     the color manager works and utilizes a color table.
  28. */
  29.  
  30. /*        First get some RAM to store the Window's ColorTable in. A window has five 
  31.         parts that can be colored. 
  32.         I will need RAM for the Color table and RAM for the 5 color specs necessary
  33.         to hold the color info for each of the window parts */
  34.         
  35.     new_color_handle = (CTabHandle)NewHandle(sizeof(ColorTable) + (5 * sizeof(ColorSpec)));    /* allocate a new color Table for this Window */
  36.     if(!new_color_handle)    /* check the handle to be certain that the Mac OS actually gave me some RAM */
  37.         { SysBeep(10); return; } /* no memory can be allocated for this color table */
  38.  
  39.  
  40. /*        Now initialize the ColorTable to these values to start with, don't worry, I
  41.             just made the RGB numbers up, they have no special significance.
  42.         Page V-202 of Inside Macintosh gives detailed info on the definitions 
  43.             of the fields and the values they can take on 
  44. */
  45.  
  46.     (*new_color_handle)->ctSize = 4;    /* This is the Color Table Size parameter, there are 5 parts to a window that can be colored, they are numbered 0 thru 4 */
  47.  
  48.     (*new_color_handle)->ctTable[0].value = wContentColor;    /* The "value" fields in 
  49.                                                                 the color table tell 
  50.                                                                 the Color manager which 
  51.                                                                 part of the window this
  52.                                                                 color definition record 
  53.                                                                 is for. I hope you know 
  54.                                                                 what the content region 
  55.                                                                 of a window is */
  56.     (*new_color_handle)->ctTable[0].rgb.red = 0;
  57.     (*new_color_handle)->ctTable[0].rgb.green = 56;
  58.     (*new_color_handle)->ctTable[0].rgb.blue = 56789;
  59.     
  60.     (*new_color_handle)->ctTable[1].value = wFrameColor;    /* define the Window Frame color */
  61.     (*new_color_handle)->ctTable[1].rgb.red = 0;
  62.     (*new_color_handle)->ctTable[1].rgb.green = 6789;
  63.     (*new_color_handle)->ctTable[1].rgb.blue = 20000;
  64.     
  65.     (*new_color_handle)->ctTable[2].value = wTextColor;        /* this is for the text in the title bar, not the text edit text */
  66.     (*new_color_handle)->ctTable[2].rgb.red = 65535;
  67.     (*new_color_handle)->ctTable[2].rgb.green = 65535;
  68.     (*new_color_handle)->ctTable[2].rgb.blue = 65535;
  69.     
  70.     (*new_color_handle)->ctTable[3].value = wHiliteColor;    /* this is for hiliting the window' title bar when the window is activated */
  71.     (*new_color_handle)->ctTable[3].rgb.red = 0;
  72.     (*new_color_handle)->ctTable[3].rgb.green = 32434;
  73.     (*new_color_handle)->ctTable[3].rgb.blue = 0;
  74.     
  75.     (*new_color_handle)->ctTable[4].value = wTitleBarColor;
  76.     (*new_color_handle)->ctTable[4].rgb.red = 65535;
  77.     (*new_color_handle)->ctTable[4].rgb.green = 0;
  78.     (*new_color_handle)->ctTable[4].rgb.blue = 20000;
  79.     
  80.     HLock(new_color_handle);                /* Lock it just in case SetWinColor de-references the Handle */
  81.     SetWinColor(aWindow, new_color_handle);    /* now give the color manager the color table to be associated with the window */
  82.     HUnlock(new_color_handle);                /* Now that SetWinColor is done, I'll unlock the handle */
  83.  
  84. /*
  85.     Since the window is now nicely colored, I'll also color the controls .....
  86. */
  87.     peek = (CWindowPeek)aWindow;
  88.     control = peek->controlList;    /* start with the window's first control .....*/
  89.     while(control)                    /* for each control, set its respective parts 
  90.                                         to these color values */
  91.     {
  92.     /*        first create a color table for the control */
  93.         new_color_handle = (CTabHandle)NewHandle(sizeof(ColorTable) + (4 * sizeof(ColorSpec)));    /* allocate a new color Table for this control */
  94.         if(!new_color_handle)
  95.             { SysBeep(10); return; } /* no memory can be allocated for this color table */
  96.  
  97.     /* 
  98.         now initialize the elements of the color table to these values.
  99.         (Page V-218 of Inside Macintosh gives details of the Control's color table
  100.         and how the SetCtlColor routine works.)
  101.      */
  102.         (*new_color_handle)->ctSize = 3;                        /* The Color Table Size is for 4 elements, numbered 0 thru 3 */
  103.         (*new_color_handle)->ctTable[0].value = cFrameColor;    /* set the Control's Frame color to this value */
  104.         (*new_color_handle)->ctTable[0].rgb.red = 0;
  105.         (*new_color_handle)->ctTable[0].rgb.green = 0;
  106.         (*new_color_handle)->ctTable[0].rgb.blue = 0;
  107.         
  108.         (*new_color_handle)->ctTable[1].value = cBodyColor;
  109.         (*new_color_handle)->ctTable[1].rgb.red = 23456;
  110.         (*new_color_handle)->ctTable[1].rgb.green = 30000;
  111.         (*new_color_handle)->ctTable[1].rgb.blue = 65535;
  112.     
  113.         (*new_color_handle)->ctTable[2].value = cTextColor;    /* this is for any text in the control, scroll bars usually don't have text in them */
  114.         (*new_color_handle)->ctTable[2].rgb.red = 65535;
  115.         (*new_color_handle)->ctTable[2].rgb.green = 0;
  116.         (*new_color_handle)->ctTable[2].rgb.blue = 65535;
  117.     
  118.         (*new_color_handle)->ctTable[3].value = cThumbColor;
  119.         (*new_color_handle)->ctTable[3].rgb.red = 0;
  120.         (*new_color_handle)->ctTable[3].rgb.green = 65535;
  121.         (*new_color_handle)->ctTable[3].rgb.blue = 0;
  122.         
  123.         HLock(new_color_handle);                /* Lock it just in case SetWinColor de-references the Handle */
  124.         SetCtlColor(control, new_color_handle);    /* now give the color manager the color table */
  125.         HUnlock(new_color_handle);                /* Now that SetWinColor is done, I'll unlock the handle */
  126.     
  127.         control = (*control)->nextControl;
  128.     }
  129.  
  130.     SetPort(savedPort);            /* restore the original Graf Port */
  131. }
  132.  
  133.